package com.scau.yangsuiyu.estore.controller.seller.manageShop;

import com.scau.yangsuiyu.estore.dababases.entity.Seller;
import de.felixroske.jfxsupport.FXMLController;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author suiyu_yang
 * @description 卖家商铺管理界面Controller
 * @date 2019-06-08 14:33
 * @email suiyu_yang@163.com
 */
//@FXMLController
public class ManageSellerShop extends AnchorPane implements Initializable {
    private Seller seller;

    @FXML
    private AnchorPane manageShopPane;

    @FXML
    private VBox toolVBox;

    @FXML
    private Button nullShopButton;

    @FXML
    private Label nullShopLabel;


    public ManageSellerShop(Seller seller) {
        this.seller = seller;
        loadFXML();
    }

    private void loadFXML() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/seller/manageShop/ManageShop.fxml"));
        fxmlLoader.setController(this);
        fxmlLoader.setRoot(this);
        try {
            fxmlLoader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        if (seller.getShop() == null) {
            nullShopButton.setVisible(true);
            nullShopLabel.setVisible(true);
            toolVBox.setVisible(false);
        } else {
            nullShopButton.setVisible(false);
            nullShopLabel.setVisible(false);
            toolVBox.setVisible(true);
            manageShopPane.getChildren().clear();
            manageShopPane.getChildren().add(new InfoShopSeller(seller));
        }
    }

    @FXML
    private void registerClick() {
        if (seller.getShop() == null) {
            manageShopPane.getChildren().add(new CreateShopPane(seller, this));
            nullShopButton.setVisible(false);
            nullShopLabel.setVisible(false);

        } else {
            nullShopButton.setVisible(false);
            nullShopLabel.setVisible(false);
            toolVBox.setVisible(true);
        }

    }

    @FXML
    private void gotoInfoShopPane() {
        manageShopPane.getChildren().clear();
        manageShopPane.getChildren().add(new InfoShopSeller(seller));
    }

    @FXML
    private void gotoShopGoodsPane() {
        manageShopPane.getChildren().clear();
        manageShopPane.getChildren().add(new ShopGoodsManagePane(seller.getShop()));
    }

    /**
     * 为manageShopPane提供一个返回商铺管理界面的接口
     */
    public void returnMainPane() {
        toolVBox.setVisible(true);
        manageShopPane.getChildren().clear();
        manageShopPane.getChildren().add(new InfoShopSeller(seller));
    }
}
